<template>
	<view class="container bar">
		<cu-custom bgColor="bg-white" :isBack="step==0?true:false">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}({{step+1}}/2)</block>
		</cu-custom>
		<view class="postform" v-if="step==0">
			<view class="head">
				<view class="cover" v-if="data.imgurl">
					<image :src="data.imgurl" mode="widthFix"></image>
					<button @click="ChooseCover" class="cu-btn bg-yellow sm round text-white">重新上传</button>
				</view>
				<view @click="ChooseCover" class="uploader text-center" v-else>
					<view class="nocover">
						<image src="@/static/images/img_no_cover.png" mode="aspectFit"></image>
					</view>
					<view class="text-muted padding-xs">
						<text>点击添加课程封面</text>
					</view>
				</view>
			</view>
			<view class="padding padding-top-xs">
				<view class="cu-form-group flex flex-direction must">
					<view class="text-boldm">课程标题</view>
					<view class="input-block">
						<input placeholder="给课程起一个有趣的标题" v-model="postdata.coursebrief" name="coursebrief"></input>
					</view>
				</view>
				<view class="cu-form-group flex flex-direction must">
					<view class="text-boldm">课程分类</view>
					<view class="input-block justify-between flex" @click="showmodal='categorys'">
						<view class="text-xl" :class="postdata.cid==0?'text-gray':''">{{catename}}</view>
						<view class="text-xl">
							<text class="text-muted cuIcon-right"></text>
						</view>
						
					</view>
				</view>
				<view class="cu-form-group flex flex-direction">
					<view class="text-boldm">所属专栏</view>
					<view class="input-block justify-between flex" @click="showmodal='specials'">
						<view class="text-xl" :class="postdata.sid==0?'text-gray':''">{{specialname}}</view>
						<view class="text-xl">
							<text class="text-muted cuIcon-right"></text>
						</view>
					</view>
				</view>
				<view v-if="data.lesson.id==0" class="cu-form-group">
					<view class="text-boldm">课程章节</view>
					<radio-group @change="ChangeMultiple">
						<label>
							<radio class='red radio' :disabled="data.lesson.id>0?true:false" :class="postdata.section=='多章节'?'checked':''" :checked="postdata.section=='多章节'?true:false" value="多章节"></radio>
							<text class="padding-left-sm" :class="data.lesson.id>0&&postdata.section=='多章节'?'text-gray':''">多章节</text>
						</label>
						<label class="margin-left padding-left">
							<radio class='red radio' :disabled="data.lesson.id>0?true:false" :class="postdata.section=='单章节'?'checked':''" :checked="postdata.section=='单章节'?true:false" value="单章节"></radio>
							<text class="padding-left-sm" :class="data.lesson.id>0&&postdata.section=='单章节'?'text-gray':''">单章节</text>
						</label>
					</radio-group>
				</view>
				<view v-if="data.lesson.id==0" style="padding-top: 0; margin-top: -30upx;" class="padding-sm text-orange padding-left text-sm">提交后不可修改</view>
				<view class="cu-form-group border-top" v-if="postdata.status">
					<view class="text-boldm">课程状态</view>
					<radio-group @change="ChangeStatus">
						<label>
							<radio class='red radio' :class="postdata.status==1?'checked':''" :checked="postdata.status==1?true:false" value="1"></radio>
							<text class="padding-left-sm">上架</text>
						</label>
						<label class="margin-left padding-left">
							<radio class='red radio' :class="postdata.status==2?'checked':''" :checked="postdata.status==2?true:false" value="2"></radio>
							<text class="padding-left-sm">下架</text>
						</label>
					</radio-group>
				</view>
				<view class="cu-form-group border-top" v-if="postdata.section=='多章节'">
					<view class="text-boldm">更新情况</view>
					<radio-group @change="ChangeUpdating">
						<label>
							<radio class='red radio' :class="postdata.updating==1?'checked':''" :checked="postdata.updating==1?true:false" value="1"></radio>
							<text class="padding-left-sm">连载中</text>
						</label>
						<label class="margin-left padding-left">
							<radio class='red radio' :class="postdata.updating==0?'checked':''" :checked="postdata.updating==0?true:false" value="0"></radio>
							<text class="padding-left-sm">已完结</text>
						</label>
					</radio-group>
				</view>
				<view v-else>
					<view class="cu-form-group border-top">
						<view class="text-boldm">课程类型</view>
						<radio-group @change="ChangeSectype">
							<label>
								<radio class='red radio' :class="sectiondata.type==0?'checked':''" :checked="sectiondata.type==0?true:false" value="0"></radio>
								<text class="padding-left-xs">视频</text>
							</label>
							<label class="margin-left-sm padding-left-xs">
								<radio class='red radio disabled' disabled :class="sectiondata.type==1?'checked':''" :checked="sectiondata.type==1?true:false" value="1"></radio>
								<text class="padding-left-xs text-gray">音频</text>
							</label>
							<label class="margin-left-sm padding-left-xs">
								<radio class='red radio disabled' disabled :class="sectiondata.type==2?'checked':''" :checked="sectiondata.type==2?true:false" value="2"></radio>
								<text class="padding-left-xs text-gray">图文</text>
							</label>
						</radio-group>
					</view>
					<view class="cu-form-group must" v-if="sectiondata.type<2">
						<view class="text-boldm">{{sectiondata.type==0?'视':'音'}}频时长</view>
						<view class="input-block">
							<input placeholder="例如:1小时5分" v-model="sectiondata.duration" name="duration"></input>
						</view>
					</view>
					<view class="padding-left padding-right" v-if="sectiondata.type==0">
						<view class="bg-gray text-center radius padding-top-xl padding-bottom" v-if="sectiondata.videourl!=''">
							<view class="text-xxxl">
								<text class="cuIcon-roundcheck text-green"></text>
							</view>
							<text class="text-green">视频已上传</text>
							<view class="cu-bar btn-group padding">
								<button class="cu-btn bg-green shadow-blur round" @click="showmodal='previewvideo'">预览</button>
								<button class="cu-btn bg-red shadow-blur round" @click="ChooseVideo">重新上传</button>
							</view>
						</view>
						<view @click="ChooseVideo" class="bg-gray text-center radius padding-top-xl padding-bottom-xl" v-else>
							<view class="text-xxxl">
								<text class="cuIcon-add text-gray"></text>
							</view>
							<text class="text-muted">上传课程视频</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="postform border-top" v-if="step==1">
			<view class="padding padding-top-xs padding-bottom-xs">
				<view class="cu-form-group">
					<view class="text-boldm">课程收费</view>
					<switch @change="ChangeFree" class="yellow" :class="isfree?'':'checked'" :checked="isfree?false:true"></switch>
				</view>
				<view v-if="!isfree" class="border-top specs">
					<view class="cu-form-group sub-form">
						<view class="text-boldm">永久</view>
						<view class="input-block flex justify-end">
							<input type="digit" placeholder="输入价格" v-model="postdata.courseprice" name="courseprice"></input>
							<text class="text-xl text-gray">元</text>
							<view class="text-xl text-white padding-left-sm"><text class="cuIcon-close"></text></view>
						</view>
					</view>
					<view class="cu-form-group sub-form" v-for="(item, index) in data.specs" :key="index">
						<view class="text-boldm">{{item.timelimit}}天</view>
						<view class="input-block flex justify-end">
							<input type="digit" placeholder="输入价格" v-model="item.courseprice" name="courseprice"></input>
							<text class="text-xl text-gray">元</text>
							<view @click="RemoveSpec(item.id)" class="text-xl text-red padding-left-sm"><text class="cuIcon-close"></text></view>
						</view>
					</view>
					<view>
						<view class="cu-form-group sub-form" v-for="(spec, idx) in addspecs" :key="idx">
							<view class="text-boldm">{{spec.timelimit}}天</view>
							<view class="input-block flex justify-end">
								<input type="digit" placeholder="输入价格" v-model="spec.courseprice" name="courseprice"></input>
								<text class="text-xl text-gray">元</text>
								<view @click="DelSpec(idx)" class="text-xl text-red padding-left-sm"><text class="cuIcon-close"></text></view>
							</view>
						</view>
					</view>
					<view class="text-center text-xxl text-grey border-top padding-top-sm" @click="showmodal='addspec'">
						<text class="cuIcon-roundadd"></text>
					</view>
				</view>
			</view>
			<view class="padding padding-top-xs padding-bottom-xs margin-top-sm">
				<view class="cu-form-group">
					<view class="text-boldm">关联商品</view>
					<switch @change="ChangeGoods" class="yellow" :class="postdata.goods.switch==0?'':'checked'" :checked="postdata.goods.switch==0?false:true"></switch>
				</view>
				<view v-if="postdata.goods.switch>0" class="border-top">
					<view class="cu-form-group sub-form" v-if="postdata.goods.title!=''">
						<view class="text-boldm">关联商品</view>
						<view class="input-block arrow text-cut">
							<text class="text-xl text-gray text-cut block">{{postdata.goods.title}}</text>
						</view>
					</view>
					<view @click="unSupport" class="text-center text-xxl text-grey border-top padding-top-sm" v-else>
						<text class="cuIcon-roundadd"></text>
					</view>
				</view>
			</view>
			<view class="padding padding-bottom-xs padding-top-xs margin-top-sm">
				<view class="cu-form-group flex flex-direction">
					<view class="text-boldm">课程标签</view>
					<view class="input-block justify-between flex" @click="showmodal='showtags'">
						<view class="text-xl" :class="postdata.tags.length==0?'text-gray':''">
							<text v-if="postdata.tags.length==0">请选则课程标签</text>
							<text v-else v-for="(tag, index) in postdata.tags" :key="index" class="cu-tag light bg-pink round">{{tag}}</text>
						</view>
						<view class="text-xl">
							<text class="text-muted cuIcon-right"></text>
						</view>
					</view>
				</view>
				<view class="cu-form-group flex flex-direction">
					<view class="text-boldm">课程难度</view>
					<view class="input-block">
						<picker @change="ChangeDifficulty" :range="difficultys" :value="gradedifficulty"><text class="text-xl">{{postdata.gradedifficulty}}</text></picker>
					</view>
				</view>
			</view>
			<view class="padding padding-bottom-xs padding-top-xs margin-top-sm">
				<view class="cu-form-group flex flex-direction">
					<view class="text-boldm">副标题</view>
					<view class="input-block">
						<input type="text" placeholder="将显示在标题下方" v-model="postdata.courseSubhead" name="subtitle"></input>
					</view>
				</view>
				<view class="cu-form-group text-xl">
					<textarea maxlength="-1" placeholder="请输入课程简介" v-model="postdata.summary"></textarea>
				</view>
				<view class="text-center padding-top-sm">
					<text class="text-gray">更多课程资料请登录PC端讲师面板完善</text>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="showmodal=='addspec'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">新增课程规格</view>
					<view class="action" @tap="showmodal=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding bg-white">
					<view class="cu-form-group">
						<view class="title">售价</view>
						<input type="digit" v-model="newspec.courseprice" placeholder="单位为元" name="input"></input>
					</view>
					<view class="cu-form-group">
						<view class="title">有效期</view>
						<input type="number" v-model="newspec.timelimit" placeholder="单位为天" name="input"></input>
					</view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-green" @tap="showmodal=''">取消</button>
						<button class="cu-btn bg-green margin-left" @tap="AddSpec(newspec.timelimit,newspec.courseprice)">确定</button>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="showmodal=='specials'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择专栏</view>
					<view class="action" @tap="showmodal=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding padding-top-xs specials bg-white">
					<view class="text-center text-empty" v-if="data.specials.length==0">
						<text>暂无可选专栏</text>
					</view>
					<scroll-view v-else scroll-y scroll-with-animation class="speciallist">
						<view class="cu-card article bg-white">
							<view class="cu-item shadow" :class="postdata.sid==item.id?'active':''" @click="ChooseSpecial(item.id,item.title)" v-for="(item, index) in data.specials" :key="index">
								<view class="content">
									<image class="cover" :src="item.imgUrl" mode="aspectFill"></image>
									<view class="desc">
										<view class="title">{{item.title}}</view>
										<view class="text-content text-warp">{{item.courseSubhead}}</view>
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-yellow text-yellow" @tap="naviTo('special/post')">新增专栏</button>
						<button class="cu-btn bg-green margin-left" @tap="showmodal=''">确定</button>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="showmodal=='previewvideo'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">预览视频</view>
					<view class="action" @tap="showmodal=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl" v-if="showmodal=='previewvideo'">
					<video v-if="videourl!=''" id="myVideo" autoplay="true" show-mute-btn="true" :src="videourl" :poster="data.cover" initial-time="0"></video>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-green" @tap="ChooseVideo">重新上传</button>
						<button class="cu-btn bg-green margin-left" @tap="showmodal=''">确定</button>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="showmodal=='showtags'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择标签(最多3个)s</view>
					<view class="action" @tap="showmodal=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xs bg-white padding-bottom">
					<view class="grid col-4">
						<view class="padding-xs" @click="taptags(item.name,item.id)" v-for="(item, k) in data.tags" :key="k">
							<view class="padding-xs text-center light" :class="postdata.tags.indexOf(item.name)>-1?'bg-red':'bg-grey'">
								<view>{{item.name}}z</view>
							</view>
						</view>
					</view>
				</view>
				<view class="cu-bar tabbar bg-white border-top">
					<view class="submit" @tap="postdata.tags=[]">重置</view>
					<view class="submit bg-gradual-yellow" @tap="showmodal=''">确定</view>
				</view>
			</view>
		</view>
		<view class="cu-modal categorys" style="top: 0;" :class="showmodal=='categorys'?'show':''">
			<view class="cu-dialog" style="vertical-align:middle; width: 98vw;">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择课程分类</view>
					<view class="action" @tap="showmodal=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xs bg-white padding-bottom">
					<scroll-view scroll-y scroll-with-animation class="">
						<view class="grid col-4" v-for="(cate, index) in data.categorys" :key="index">
							<view class="padding-xs">
								<view class="padding-xs text-center light" @click="ChangeCate(cate.id,cate.name)" :class="postdata.cid==cate.id?'bg-red':'bg-grey'">
									<view class="text-bold text-lg">{{cate.name}}</view>
								</view>
							</view>
							<view class="padding-xs" v-for="(item, k) in cate.subcates" :key="k">
								<view class="padding-xs text-center light" @click="ChangeCate(item.id,item.title)" :class="postdata.cid==item.id?'bg-red':'bg-grey'">
									<view>{{item.title}}</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="cu-bar tabbar bg-white border-top">
					<view class="submit" @tap="postdata.cid=0">重置</view>
					<view class="submit bg-gradual-yellow" @tap="showmodal=''">确定</view>
				</view>
			</view>
		</view>
		<view class="cu-bar tabbar">
			<view class="action" v-if="step==0">
				<view class="flex padding-left-xl padding-right-xl padding-bottom-sm">
					<button class="cu-btn bg-gradual-yellow round-bottomleft-only lg flex-sub" @click="step=1">下一步</button>
					<button class="cu-btn bg-orange-red round-right-only lg flex-sub" @click="SubmitPost">保存</button>
				</view>
			</view>
			<view class="action" v-if="step==1">
				<view class="flex padding-left-xl padding-right-xl padding-bottom-sm">
					<button class="cu-btn bg-gradual-yellow round-bottomleft-only lg flex-sub" @click="step=0">上一步</button>
					<button class="cu-btn bg-orange-red round-right-only lg flex-sub" @click="SubmitPost">保存</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import core from "@/static/core.js"
	
	export default {
		data() {
			return {
				id:0,
				step:0,
				lecturer:0,
				showmodal:'',
				postdata:{
					imgurl:"",
					coursebrief:"",
					section:'多章节',
					updating:0,
					cid:0,
					sid:0,
					tags:[],
					gradedifficulty:'入门课',
					courseSubhead:'',
					summary:'',
					courseprice:0.00,
					goods:{
						id:0,
						switch:0,
						title:"",
						url:"",
						cover:"",
						summary:""
					},
					status:1
				},
				sectiondata:{
					id:0,
					type:0,
					title:"",
					cover:"",
					duration:"",
					videourl:""
				},
				addspecs:[],
				newspec:{
					timelimit:'',
					courseprice:''
				},
				gradedifficulty:0,
				specialname:'请选择课程所在专栏',
				isfree:true,
				videourl:"",
				difficultys:['入门课','基础课','进阶课','高难度','专业级'],
				catename:"请选则课程分类",
				data:{
					title:"发布课程",
					imgurl:'',
					categorys:[],
					specs:[],
					tags:[],
					section:{
						id:0
					},
					specials:[],
					videourl:"",
					lesson:{
						id:0
					}
				}
			}
		},
		onLoad(options) {
			if(typeof(options.id)!='undefined') this.id = options.id;
			if(core.userinfo.uid==0) return core.toast('请先登录','login');
			var that = this;
			this.initData('lesson/post',{id:this.id},function(res){
				if(res.lesson.id>0){
					for(let i in that.postdata){
						that.postdata[i] = res.lesson[i];
					}
					that.catename = res.lesson.category;
					that.isfree = res.lesson.price>0 ? false : true;
					that.videourl = res.videourl;
					if(res.section.id>0){
						that.sectiondata = res.section;
					}
					if(res.lesson.sid>0){
						that.specialname = res.lesson.special;
					}
				}
			});
			console.log(this.data)
			console.log(this.postdata)
		},
		methods:{
			async initData(route, data={}, callback=false){
				var that = this;
				// core.get(route,function(res){
					// if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
					// 	return core.report(res, true);
					// }
					// that.data = res;
					that.data.tags=(await this.$api.reqGet({
						url:"menu/selCourseType/0",
					})).data;
					that.data.categorys=(await this.$api.reqGet({
						url:"menu/selFiltrate",
					})).data;
					console.log(that.data.categorys)
					this.data.specials=(await this.$api.reqGet({
						url:"column/selsta",
					})).data;
					(await this.$api.reqGet({
						url:"lecturer/selectByUid/"+core.userinfo.uid
					}).then(res=>{
						this.lecturer=res.data.id;
						console.log(this.lecturer)
					}))
					if(this.id!=0){
						(await this.$api.reqGet({
							url:"menu/selById/"+this.id
						}).then(res=>{
							console.log(res)
							if(res.code==200){
								this.postdata=res.data;
								this.postdata.goods=[];
								this.postdata.tags=[];
								this.data.imgurl=this.postdata.imgurl;
								if(this.postdata.courseprice>0){
									this.isfree=false;
								}
								for(var a in this.data.categorys){
									if(this.postdata.cid==this.data.categorys[a].id){
										this.ChangeCate(this.postdata.cid,this.data.categorys[a].name);
									}
								}
								console.log(this.postdata.sid)
								for(var a in this.data.specials){
									if(this.postdata.sid==this.data.specials[a].id){
										this.ChooseSpecial(this.postdata.sid,this.data.specials[a].title);
									}
								}
								var arr=this.postdata.typeId.split(',');
								console.log(this.postdata)
								for(var i=0;i<arr.length;i++){
									for(var j=0;j<this.data.tags.length;j++){
										if(arr[i]==this.data.tags[j].id){
											this.postdata.tags.push(this.data.tags[j].name)
										}
									}
								}
								console.log(this.postdata.tags)
							}
						}))
					}
					// uni.setNavigationBarTitle({
					// 	title:res.title
					// });
					// if(callback){
					// 	callback(res);
					// }
				// },data);
			},
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			unSupport(){
				return core.toast('敬请期待');
			},
			ChangeMultiple(e){
				this.postdata.section = e.detail.value;
			},
			ChangeUpdating(e){
				this.postdata.updating = e.detail.value;
			},
			ChangeStatus(e){
				this.postdata.status = e.detail.value;
			},
			ChangeSectype(e){
				this.sectiondata.type = e.detail.value;
			},
			ChangeDifficulty(e){
				this.gradedifficulty = e.detail.value;
				this.postdata.gradedifficulty = this.difficultys[e.detail.value];
			},
			ChangeFree(e){
				this.isfree = !e.detail.value;
			},
			ChangeGoods(e){
				this.postdata.goods.switch = e.detail.value ? 2 : 0;
			},
			ChangeCate(cid,cname){
				this.postdata.cid = cid;
				this.catename = cname;
			},
			ChooseSpecial(sid,name){
				// if(sid==this.postdata.sid){
				// 	this.postdata.sid = 0;
				// 	this.specialname = '请选择课程所在专栏';
				// 	return;
				// }
				this.postdata.sid = sid;
				this.specialname = name;
			},
			ChooseCover(){
				var that = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						core.upload(res.tempFilePaths[0],function(res){
							that.data.imgurl = res.data;
							that.postdata.imgurl = res.data;
						});
					}
				});
			},
			ChooseVideo(){
				var that = this;
				uni.chooseVideo({
					compressed: false, //默认9
					count: 1,
					sourceType: ['album', 'camera'], //从相册选择
					success: (res) => {
						core.upload(res.tempFilePath,function(res){
							that.sectiondata.videourl = res.data;
							that.videourl = res.data;
						},'video');
					}
				});
			},
			taptags(tag,id){
				if(this.postdata.tags.indexOf(tag)>-1){
					this.postdata.tags.splice(this.postdata.tags.indexOf(tag), 1);
					// this.postdata.tags.splice(this.postdata.tags.indexOf(id), 1);
				}else{
					if(this.postdata.tags.length>=3) return core.toast('最多选择3个标签');
					this.postdata.tags.push(tag);
					// this.postdata.tags.push(id);
					if(this.postdata.tags.length>=3) this.showmodal = '';
				}
			},
			RemoveSpec(specid=0){
				if(!specid) return core.toast('参数错误');
				var that = this;
				return core.confirm('删除后不可恢复，是否确定要删除？','删除规格',function(){
					core.get('lesson/rmspec',function(res){
						if(res.type!='success') return core.report(res);
						that.data.specs = res.message;
					},{specid:specid,id:that.data.lesson.id});
				});
			},
			DelSpec(index){
				this.addspecs.splice(index,1);
			},
			AddSpec(timelimit=0,price=0.00){
				if(timelimit<=0) return core.toast('有效期必须大于0天');
				price = Math.floor(price*100)/100;
				if(price<=0) return core.toast('单价必须大于0元');
				this.postdata.courseprice = Math.floor(this.postdata.courseprice*100)/100;
				if(price>=this.postdata.courseprice) return core.toast('单价必须小于永久价格');
				this.addspecs.push({timelimit:timelimit,courseprice:price});
				this.showmodal = '';
				this.newspec = {
					timelimit:'',
					courseprice:''
				}
			},
			SubmitPost(){
				console.log(this.postdata);
				let postdata = this.postdata;
				let data = {id:this.id};
				// if(postdata.imgurl=='') return core.toast('请上传课程封面图片');
				if(postdata.coursebrief=='') return core.toast('课程标题不能为空');
				if(postdata.cid==0) return core.toast('请选择课程分类');
				if(this.isfree){
					postdata.courseprice = 0;
				}else{
					if(postdata.courseprice<=0) return core.toast('请输入课程价格');
					if(this.data.specs.length>0){
						let specs = [];
						for(var i in this.data.specs){
							specs.push({
								id:this.data.specs[i].id,
								courseprice:this.data.specs[i].price,
								timelimit:this.data.specs[i].timelimit
							});
						}
						data.specs = specs;
					}
					if(this.addspecs.length>0){
						data.appendprices = this.addspecs;
					}
				}
				data.data = postdata;
				if(postdata.section=='单章节'){
					if(this.sectiondata.type<2){
						if(this.sectiondata.videourl=='') return core.toast('请上传音/视频文件');
						if(this.sectiondata.duration=='') return core.toast('请输入音/视频时长');
					}
					data.data.classroomCourseDetails =[];
					this.sectiondata.imgandvideourl=this.sectiondata.videourl;
					data.data.classroomCourseDetails.push(this.sectiondata);
				}
				data.data.courseauthorid=this.lecturer;
				var tags="";
				var arr=[];
				for(var i=0;i<this.postdata.tags.length;i++){
					for(var j=0;j<this.data.tags.length;j++){
						if(this.postdata.tags[i]==this.data.tags[j].name){
							arr.push(this.data.tags[j].id)
						}
					}
				}
				for(var i=0;i<arr.length;i++){
					tags=tags+arr[i];
					if(i+1<arr.length){
						tags=tags+","
					}
				}
				data.data.typeId=tags;
				console.log(data.data);
				(this.$api.reqPost({
					url:"menu/insert",
					data:data.data
				}).then(res=>{
					console.log(res);
					if(res.code==200){
						core.toast(res.msg,'home','success');
					}
				}))
				// return core.post('lesson/post',function(res){
				// 	if(res.type!='success') return core.report(res);
				// 	core.toast(res.message,res.redirect,res.type);
				// },data);
			}
		}
	}
</script>

<style>
	page{background: #FFFFFF;}
	.container{background: #F2F2F2;}
	.cover{position: relative;}
	.cover .cu-btn{position: absolute; right: 20upx; bottom: 20upx;}
	.uploader{padding: 130upx 0; background: #F7F7F7;}
	.nocover image{width: 78upx; height: 63upx;}
	.cu-bar.tabbar .action .cu-btn{min-width: 45%;}
	.speciallist{max-height: 80vw;}
	.speciallist .cu-item.active{border:2px solid #FF5757; background-image: url(@/static/images/bg_item_selected.png); background-repeat: no-repeat; background-position: bottom right; background-size: 40upx auto;}
	.speciallist .cu-item .desc{max-width: calc(100% - 160upx);}
	.speciallist .cu-item .desc .title{max-height: 84upx; white-space: normal; text-align: left; text-overflow: unset;}
</style>
